import { reqGetGoodsData } from "@/api"

const state = {
  goodsInfo:{}
}
const actions = {
  // 获取搜索页面的数据
  async getGoodsData({commit},searchParams){
    let result = await reqGetGoodsData(searchParams)
    if(result.code === 200){
      commit('GET_GOODS_INFO',result.data)
      console.log(result);
    }else{
      console.log(result.message);
    }
  }
}
const mutations ={
  //存储搜索过来的商品信息，是一个对象
  GET_GOODS_INFO(state,data){
    state.goodsInfo = data
  }
}
// 相当于vue的计算属性
const getters={
  goodsList(state){
    return state.goodsInfo.goodsList
  },
  attrsList(state){
    return state.goodsInfo.attrsList
  },
  trademarkList(state){
    return state.goodsInfo.trademarkList
  },
  total(state) {
    return state.goodsInfo.total
  }
}
export default{
  namespaced:true, //命名空间,来区分不同的模块
  actions,
  mutations,
  getters,
  state
}

